var global_obj = {
  timer: "",
  check_form: function (notnull_obj, format_obj, type, is_new) {
    var flag = false,
      is_new = typeof arguments[3] == "undefined" ? 0 : 1,
      errorObj = new Object();
    if (notnull_obj) {
      if (notnull_obj.length) {
        notnull_obj.each(function () {
          var $lang = $(this).parents(".tab_txt").attr("lang");
          if (!errorObj[$lang]) {
            errorObj[$lang] = 0;
          }
          if (!$(this).find("input").length && $.trim($(this).val()) == "") {
            if ($lang) {
              errorObj[$lang] += 1;
              $(this)
                .parents(".rows")
                .find(".tab_box_btn[data-lang=" + $lang + "]")
                .addClass("empty");
              $(".r_con_wrap").animate(
                { scrollTop: $(this).parents(".rows").position().top },
                0
              );
            }
            if ($(this).attr("parent_null")) {
              $(this)
                .parent()
                .css("border", "2px solid #ff0000")
                .addClass("null");
              $(this)
                .parents("[parent_null]")
                .css("border", "2px solid #ff0000")
                .addClass("null");
            } else {
              $(this).css("border", "2px solid #ff0000").addClass("null");
              if ($(this).next(".input_tips").length) {
                $(this).next(".input_tips").show();
              } else {
                if ($(this).siblings(".input_tips").length) {
                  $(this).siblings(".input_tips").show();
                }
              }
            }
            flag == false && $(this).focus();
            flag = true;
          } else {
            if (errorObj[$lang] == 0) {
              $(this)
                .parents(".rows")
                .find(".tab_box_btn[data-lang=" + $lang + "]")
                .removeClass("empty");
            }
            if ($(this).attr("parent_null")) {
              $(this)
                .parents("[parent_null]")
                .removeAttr("style")
                .removeClass("null");
            } else {
              $(this).removeAttr("style").removeClass("null");
              if ($(this).next(".input_tips").length) {
                $(this).next(".input_tips").hide();
              }
            }
          }
        });
        $(".rows").find(".tab_box_row .tips").hide();
        $(".rows")
          .find(".tab_box_row .tab_box_btn")
          .each(function () {
            if ($(this).hasClass("empty")) {
              $(this).parents(".tab_box_row").find(".tips").show();
            }
          });
        if (flag) {
          return flag;
        }
      }
    }
    if (format_obj) {
      if (format_obj.length) {
        var reg = {
          MobilePhone: /^1[34578]\d{9}$/,
          Telephone: /^(0\d{2,3})(-)?(\d{7,8})(-)?(\d{3,})?$/,
          Fax: /^(0\d{2,3})(-)?(\d{7,8})(-)?(\d{3,})?$/,
          Email: /^\w+[a-zA-Z0-9-.+_]+@[a-zA-Z0-9-.+_]+\.\w*$/,
          Length: /^.*/,
        };
        var tips = {
          MobilePhone: lang_obj.format.mobilephone,
          Telephone: lang_obj.format.telephone,
          Fax: lang_obj.format.fax,
          Email: lang_obj.format.email,
          Length: lang_obj.format.length,
        };
        if (type == 1) {
          format_obj.each(function () {
            var o = $(this);
            if ($.trim(o.val())) {
              if (reg[o.attr("format")].test($.trim(o.val())) === false) {
                o.css("border", "1px solid red").addClass("null");
                o.focus();
                flag = true;
              }
            }
          });
        } else {
          format_obj.each(function () {
            var o = $(this);
            var s = o.attr("format").split("|");
            if (!$.trim(o.val())) {
              flag = false;
            } else if (
              (s[0] == "Length" && $.trim(o.val()).length != parseInt(s[1])) ||
              (s[0] != "Length" && reg[s[0]].test($.trim(o.val())) === false)
            ) {
              if (is_new == 1) {
                global_obj.new_win_alert(
                  tips[s[0]].replace("%num%", s[1]),
                  function () {},
                  undefined,
                  undefined,
                  "fail"
                );
              } else {
                global_obj.win_alert(tips[s[0]].replace("%num%", s[1]));
              }
              o.css("border", "1px solid red").addClass("null");
              o.focus();
              flag = true;
              return false;
            }
          });
        }
      }
    }
    return flag;
  },
  win_alert: function (tips, callback, type, is_pop, status) {
    var type = typeof arguments[2] == "undefined" ? "alert" : arguments[2],
      is_pop = typeof arguments[3] == "undefined" ? 0 : 1,
      status = typeof arguments[4] == "undefined" ? "" : arguments[4],
      not_remove_mask = $(".not_remove_mask:visible").length ? 1 : 0,
      html;
    $("#div_mask, .win_alert").remove();
    global_obj.div_mask();
    html = '<div class="win_alert">';
    html += '<div class="win_close"><button class="close">x</button></div>';
    html += '<div class="win_tips ' + status + '">' + tips + "</div>";
    html += '<div class="win_btns">';
    if (type == "confirm") {
      html +=
        '<button class="btn btn_sure">' + lang_obj.global.confirm + "</button>";
      html +=
        '<button class="btn btn_cancel">' +
        lang_obj.global.cancel +
        "</button>";
    } else {
      html +=
        '<button class="btn btn_sure btn_once_sure">' +
        lang_obj.global.confirm +
        "</button>";
    }
    html += "</div>";
    html += "</div>";
    $("body").prepend(html);
    $(".win_alert").css({
      left: $(window).width() / 2 - $(".win_alert").outerWidth(true) / 2,
      top: "30%",
    });
    if (type == "confirm") {
      $(".win_alert")
        .delegate(".close, .btn_cancel", "click", function () {
          $(".win_alert").remove();
          is_pop == 0 && not_remove_mask == 0 && global_obj.div_mask(1);
        })
        .delegate(".btn_sure", "click", function () {
          $.isFunction(callback) && callback();
          $(".win_alert .close").click();
        });
    } else {
      $(".win_alert").delegate(".close, .btn_sure", "click", function () {
        $.isFunction(callback) && callback();
        $(".win_alert").remove();
        is_pop == 0 && not_remove_mask == 0 && global_obj.div_mask(1);
      });
    }
    return false;
  },
  new_win_alert: function (tips, callback, type, is_pop, status, btn) {
    var type = typeof arguments[2] == "undefined" ? "alert" : arguments[2],
      is_pop = typeof arguments[3] == "undefined" ? 0 : 1,
      status = typeof arguments[4] == "undefined" ? "await" : arguments[4],
      btn =
        typeof arguments[5] == "undefined"
          ? lang_obj.global.confirm
          : arguments[5],
      html;
    var little_tips = lang_obj.user.company.examine_tips;
    $("#div_mask, .new_win_alert").remove();
    global_obj.div_mask();
    html = '<div class="new_win_alert themes_popups">';
    html += '<div class="win_close"><button class="close"></button></div>';
    html += '<div class="win_tips">';
    if (status == "auto_success") {
      html += '<div class="register_top">';
    }
    if (status != "none") {
      html += '<i class="icon_success_status ' + status + '"></i>';
    }
    html += tips;
    if (type == "check") {
      html += '<div class="little_tips">' + little_tips + "</div>";
    }
    html += "</div>";
    html += '<div class="win_btns">';
    html += '<button class="btn btn_sure">' + btn + "</button>";
    if (type == "confirm")
      html +=
        '<button class="btn btn_cancel">' +
        lang_obj.global.cancel +
        "</button>";
    html += '<div class="clear"></div>';
    html += "</div>";
    html += "</div>";
    $("body").prepend(html);
    if (type == "check") {
      clearTimeout(global_obj.timer);
    }
    if (status == "auto_success") {
      $(".icon_success_status.auto_success").addClass("cur");
      $(".new_win_alert").addClass("reg_success");
    } else {
      $(".new_win_alert").css({
        left: $(window).width() / 2 - $(".new_win_alert").outerWidth() / 2,
        top: "30%",
      });
    }
    if (type == "confirm") {
      $(".new_win_alert")
        .delegate(".close, .btn_cancel", "click", function () {
          $(".new_win_alert").remove();
          is_pop == 0 && global_obj.div_mask(1);
        })
        .delegate(".btn_sure", "click", function () {
          $.isFunction(callback) && callback();
          $(".new_win_alert .close").click();
        });
    } else {
      $(".new_win_alert").delegate(".close", "click", function () {
        $(".new_win_alert").remove();
        global_obj.div_mask(1);
      });
      $(".new_win_alert").delegate(".btn_sure", "click", function () {
        $.isFunction(callback) && callback();
        $(".new_win_alert").remove();
        is_pop == 0 && global_obj.div_mask(1);
      });
    }
    return false;
  },
  win_alert_auto_close: function (
    tips,
    status,
    time,
    pos_top,
    no_remove_mask,
    callback,
    is_pop,
    no_remove = 0
  ) {
    var status = typeof arguments[1] == "undefined" ? "await" : arguments[1],
      time =
        typeof arguments[2] == "undefined" || !arguments[2]
          ? "2000"
          : arguments[2],
      pos_top =
        typeof arguments[3] == "undefined" || !arguments[3]
          ? "40%"
          : arguments[3],
      no_remove_mask = typeof arguments[4] == "undefined" ? 1 : arguments[4],
      is_pop = typeof arguments[6] == "undefined" ? 0 : 1,
      html = "";
    if (no_remove_mask) $("#div_mask, .new_win_alert").remove();
    if (status != "loading" || (status == "loading" && time == -1)) {
      html +=
        '<div class="new_win_alert win_alert_auto_close' +
        (status == "loading" ? " win_alert_loading" : "") +
        '">';
      html += '<div class="win_close"><button class="close"></button></div>';
      html += '<div class="win_tips">';
      if (status != "loading") {
        html += '<i class="icon_success_status ' + status + '"></i>';
      }
      html += tips + "</div>";
      html += "</div>";
      $("body").prepend(html);
      $(".new_win_alert").css({
        left: $(window).width() / 2 - $(".new_win_alert").outerWidth(true) / 2,
        top: pos_top,
      });
    }
    clearTimeout(global_obj.timer);
    $(".new_win_alert").delegate(".close", "click", function () {
      $.isFunction(callback) && callback();
      $(".new_win_alert").remove();
      is_pop == 0 && global_obj.div_mask(1);
    });
    if (status == "success") {
      $(".icon_success_status.success").addClass("cur");
    }
    if (
      (status != "loading" || (status == "loading" && time >= 0)) &&
      !no_remove
    ) {
      global_obj.timer = setTimeout(function () {
        $.isFunction(callback) && callback();
        $(".new_win_alert").remove();
      }, time);
    }
    return false;
  },
  win_alert_confirm: function (
    tips,
    status,
    pos_top,
    no_remove_mask,
    callback,
    is_pop,
    no_remove = 0
  ) {
    var status = typeof arguments[1] == "undefined" ? "await" : arguments[1],
      pos_top =
        typeof arguments[3] == "undefined" || !arguments[3]
          ? "40%"
          : arguments[3],
      no_remove_mask = typeof arguments[4] == "undefined" ? 1 : arguments[4],
      is_pop = typeof arguments[6] == "undefined" ? 0 : 1,
      html = "";
    if (no_remove_mask) $("#div_mask, .new_win_alert").remove();
    $(".new_win_alert").delegate(".close", "click", function () {
      $.isFunction(callback) && callback();
      $(".new_win_alert").remove();
      is_pop == 0 && global_obj.div_mask(1);
    });
    return false;
  },
  div_mask: function (remove, id_name = "") {
    var obj = typeof arguments[1] == "undefined" ? "" : arguments[1],
      $obj = $("body");
    if (typeof obj == "object") $obj = obj;
    if (id_name == "") {
      id_name = "div_mask";
    }
    if (remove == 1) {
      $("#" + id_name).remove();
      $("#dequeue_next").click();
    } else {
      if (!$("#" + id_name).size()) {
        $obj.prepend('<div id="' + id_name + '"></div>');
        $("#" + id_name).css({
          width: "100%",
          height: $(document).height(),
          overflow: "hidden",
          position: "fixed",
          top: 0,
          left: 0,
          background: "#000",
          opacity: 0.6,
          "z-index": 10001,
        });
      }
    }
    $(".div_mask").hide();
  },
  data_posting: function (display, tips) {
    if (display) {
      $("body").prepend(
        '<div id="data_posting"><img src="static/image/data_posting.gif" style="margin-top: 4px;display: inline-block;vertical-align: top;" width="16" height="16" align="absmiddle" />&nbsp;&nbsp;' +
          tips +
          "</div>"
      );
      $("#data_posting").css({
        width: "188px",
        height: "24px",
        "line-height": "24px",
        padding: "0 8px",
        overflow: "hidden",
        border: "1px solid #bbb",
        background: "#ddd",
        position: "fixed",
        top: "40%",
        left: "0",
        right: "0",
        margin: "auto",
        "z-index": 10001,
      });
    } else {
      setTimeout('$("#data_posting").remove();', 500);
    }
  },
  urlencode: function (str) {
    str = (str + "").toString();
    return encodeURIComponent(str)
      .replace(/!/g, "%21")
      .replace(/'/g, "%27")
      .replace(/\(/g, "%28")
      .replace(/\)/g, "%29")
      .replace(/\*/g, "%2A")
      .replace(/%20/g, "+");
  },
  json_encode_data: function (value) {
    var result = new Object();
    if (typeof value == "string" && value) {
      if (typeof JSON == "object") {
        result = JSON.parse(value);
      } else {
        var ary, arr, key;
        ary = value.substr(1, value.length - 2).split(',"');
        for (var i = 0; i < ary.length; i++) {
          arr = ary[i].split(":");
          key = parseInt(
            isNaN(arr[0])
              ? i == 0
                ? arr[0].substr(1, arr[0].length - 2)
                : arr[0].substr(0, arr[0].length - 1)
              : arr[0]
          );
          if (arr[1].substr(0, 1) == "[") {
            result[key] = arr[1].substr(1, arr[1].length - 2).split(",");
          } else {
            result[key] = arr[1];
          }
        }
      }
    } else {
      result = value;
    }
    return result;
  },
  json_decode_data: function (value) {
    var result;
    if (typeof value == "object") {
      if (typeof JSON == "object") {
        result = JSON.stringify(value);
      } else {
        result = "";
        for (k in value) {
          if (global_obj.is_array(value[k])) {
            result += '"' + k + '":[' + value[k] + "],";
          } else {
            result += '"' + k + '":"' + value[k] + '",';
          }
        }
        result = "{" + result.substr(0, result.length - 1) + "}";
      }
    } else {
      result = value;
    }
    return result;
  },
  in_array: function (needle, arr) {
    for (var i = 0; i < arr.length && arr[i] != needle; i++);
    return !(i == arr.length);
  },
  is_array: function (data) {
    if (Object.prototype.toString.call(data) == "[object Array]") {
      return true;
    } else {
      return false;
    }
  },
  base64_encode: function (str) {
    var c1, c2, c3;
    var base64EncodeChars =
      "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
    var i = 0,
      len = str.length,
      string = "";
    while (i < len) {
      c1 = str.charCodeAt(i++) & 0xff;
      if (i == len) {
        string += base64EncodeChars.charAt(c1 >> 2);
        string += base64EncodeChars.charAt((c1 & 0x3) << 4);
        string += "==";
        break;
      }
      c2 = str.charCodeAt(i++);
      if (i == len) {
        string += base64EncodeChars.charAt(c1 >> 2);
        string += base64EncodeChars.charAt(
          ((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4)
        );
        string += base64EncodeChars.charAt((c2 & 0xf) << 2);
        string += "=";
        break;
      }
      c3 = str.charCodeAt(i++);
      string += base64EncodeChars.charAt(c1 >> 2);
      string += base64EncodeChars.charAt(
        ((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4)
      );
      string += base64EncodeChars.charAt(
        ((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6)
      );
      string += base64EncodeChars.charAt(c3 & 0x3f);
    }
    return string;
  },
  htmlspecialchars: function (str) {
    str = str.replace(/&/g, "&amp;");
    str = str.replace(/</g, "&lt;");
    str = str.replace(/>/g, "&gt;");
    str = str.replace(/"/g, "&quot;");
    str = str.replace(/'/g, "&#039;");
    return str;
  },
  htmlspecialchars_decode: function (str) {
    str = str.replace(/&amp;/g, "&");
    str = str.replace(/&lt;/g, "<");
    str = str.replace(/&gt;/g, ">");
    str = str.replace(/&quot;/g, '"');
    str = str.replace(/&#039;/g, "'");
    return str;
  },
  setCookie: function (name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie =
      name +
      "=" +
      escape(value) +
      (expiredays == null ? "" : ";expires=" + exdate.toGMTString());
  },
  getCookie: function (name) {
    if (document.cookie.length > 0) {
      start = document.cookie.indexOf(name + "=");
      if (start != -1) {
        start = start + (name.length + 1);
        end = document.cookie.indexOf(";", start);
        if (end == -1) end = document.cookie.length;
        return unescape(document.cookie.substring(start, end));
      }
    }
    return "";
  },
  delCookie: function (name, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() - 1);
    var value = global_obj.getCookie(name);
    if (value) {
      document.cookie =
        name +
        "=" +
        escape(value) +
        (expiredays == null ? "" : ";expires=" + exdate.toGMTString());
    }
  },
  Waterfall: function (container, colWidth, colCount, cls) {
    function Waterfall(param) {
      this.id =
        typeof param.container == "string"
          ? document.getElementById(param.container)
          : param.container;
      this.colWidth = param.colWidth;
      this.colCount = param.colCount || 4;
      this.cls = param.cls && param.cls != "" ? param.cls : "wf-cld";
      this.init();
    }
    Waterfall.prototype = {
      getByClass: function (cls, p) {
        var arr = [],
          reg = new RegExp("(^|\\s+)" + cls + "(\\s+|$)", "g");
        var nodes = p.getElementsByTagName("*"),
          len = nodes.length;
        for (var i = 0; i < len; i++) {
          if (reg.test(nodes[i].className)) {
            arr.push(nodes[i]);
            reg.lastIndex = 0;
          }
        }
        return arr;
      },
      maxArr: function (arr) {
        var len = arr.length,
          temp = arr[0];
        for (var ii = 1; ii < len; ii++) {
          if (temp < arr[ii]) {
            temp = arr[ii];
          }
        }
        return temp;
      },
      getMar: function (node) {
        var dis = 0;
        if (node.currentStyle) {
          dis = parseInt(node.currentStyle.marginBottom);
        } else if (document.defaultView) {
          dis = parseInt(
            document.defaultView.getComputedStyle(node, null).marginBottom
          );
        }
        return dis;
      },
      getMinCol: function (arr) {
        var ca = arr,
          cl = ca.length,
          temp = ca[0],
          minc = 0;
        for (var ci = 0; ci < cl; ci++) {
          if (temp > ca[ci]) {
            temp = ca[ci];
            minc = ci;
          }
        }
        return minc;
      },
      init: function () {
        var _this = this;
        var col = [],
          iArr = [];
        var nodes = _this.getByClass(_this.cls, _this.id),
          len = nodes.length;
        for (var i = 0; i < _this.colCount; i++) {
          col[i] = 0;
        }
        for (var i = 0; i < len; i++) {
          nodes[i].h = nodes[i].offsetHeight + _this.getMar(nodes[i]);
          iArr[i] = i;
        }
        for (var i = 0; i < len; i++) {
          var ming = _this.getMinCol(col);
          nodes[i].style.left = ming * _this.colWidth + "px";
          nodes[i].style.top = col[ming] + "px";
          col[ming] += nodes[i].h;
        }
        _this.id.style.height = _this.maxArr(col) + "px";
      },
    };
    new Waterfall({
      container: container,
      colWidth: colWidth,
      colCount: colCount,
      cls: cls,
    });
  },
  sort: function (a, b) {
    if (a.indexOf("Ov:") != -1) {
      a = 99999999;
    }
    if (b.indexOf("Ov:") != -1) {
      b = 99999999;
    }
    return a - b;
  },
  checkCharLength: function (box, content) {
    var e = $(box);
    e.change(function (event) {
      var curLength = e.val().length;
      var maxlength = e.attr("maxlength");
      if (curLength > maxlength) {
        e.val($.trim(e.val()).substr(0, maxlength)).trigger("change");
        return;
      }
      $("#review_form .font_tips em").text(curLength);
      $(content)
        .text(maxlength - curLength)
        .parent()
        .toggleClass("red", curLength > maxlength);
    }).keyup(function () {
      e.trigger("change");
    });
  },
  query_get: function (value, selecter) {
    if (selecter == "parent") {
      var query = window.parent.location.search.substring(1);
    } else {
      var query = window.location.search.substring(1);
    }
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
      var pair = vars[i].split("=");
      if (pair[0] == value) return pair[1];
    }
    return false;
  },
  dragsort: function (
    obj,
    do_action,
    dragSelector,
    dragSelectorExclude,
    placeHolderTemplate,
    itemSelector,
    callback
  ) {
    typeof dragSelector == "undefined" && (dragSelector = "tr");
    typeof dragSelectorExclude == "undefined" &&
      (dragSelectorExclude = "a, td[data!=move_myorder]");
    typeof placeHolderTemplate == "undefined" &&
      (placeHolderTemplate = '<tr class="placeHolder"></tr>');
    typeof itemSelector == "undefined" && (itemSelector = "");
    obj.dragsort({
      dragSelector: dragSelector,
      dragSelectorExclude: dragSelectorExclude,
      placeHolderTemplate: placeHolderTemplate,
      itemSelector: itemSelector,
      scrollSpeed: 5,
      dragEnd: function () {
        if (do_action) {
          var target = itemSelector ? itemSelector : dragSelector;
          var data = obj
            .find(target)
            .map(function () {
              return $(this).attr("data-id");
            })
            .get();
          $.get("?", {
            do_action: do_action,
            sort_order: data.join(","),
          });
        }
        if ($.isFunction(callback)) {
          callback();
        }
      },
    });
  },
  getMark: function () {
    let hash = window.location.hash;
    let mark = "";
    if (hash) mark = hash.substring(1);
    return mark;
  },
};
$.toJSON =
  typeof JSON == "object" && JSON.stringify
    ? JSON.stringify
    : function (e) {
        if (e === null) return "null";
        var t,
          n,
          r,
          i,
          s = $.type(e);
        if (s === "undefined") return undefined;
        if (s === "number" || s === "boolean") return String(e);
        if (s === "string") return $.quoteString(e);
        if (typeof e.toJSON == "function") return $.toJSON(e.toJSON());
        if (s === "date") {
          var o = e.getUTCMonth() + 1,
            u = e.getUTCDate(),
            a = e.getUTCFullYear(),
            f = e.getUTCHours(),
            l = e.getUTCMinutes(),
            c = e.getUTCSeconds(),
            h = e.getUTCMilliseconds();
          o < 10 && (o = "0" + o);
          u < 10 && (u = "0" + u);
          f < 10 && (f = "0" + f);
          l < 10 && (l = "0" + l);
          c < 10 && (c = "0" + c);
          h < 100 && (h = "0" + h);
          h < 10 && (h = "0" + h);
          return (
            '"' +
            a +
            "-" +
            o +
            "-" +
            u +
            "T" +
            f +
            ":" +
            l +
            ":" +
            c +
            "." +
            h +
            'Z"'
          );
        }
        t = [];
        if ($.isArray(e)) {
          for (n = 0; n < e.length; n++) t.push($.toJSON(e[n]) || "null");
          return "[" + t.join(",") + "]";
        }
        if (typeof e == "object") {
          for (n in e)
            if (hasOwn.call(e, n)) {
              s = typeof n;
              if (s === "number") r = '"' + n + '"';
              else {
                if (s !== "string") continue;
                r = $.quoteString(n);
              }
              s = typeof e[n];
              if (s !== "function" && s !== "undefined") {
                i = $.toJSON(e[n]);
                t.push(r + ":" + i);
              }
            }
          return "{" + t.join(",") + "}";
        }
      };
$.evalJSON =
  typeof JSON == "object" && JSON.parse
    ? JSON.parse
    : function (str) {
        return eval("(" + str + ")");
      };
var meta = {
    "\b": "\\b",
    "\t": "\\t",
    "\n": "\\n",
    "\f": "\\f",
    "\r": "\\r",
    '"': '\\"',
    "\\": "\\\\",
  },
  hasOwn = Object.prototype.hasOwnProperty;
$.quoteString = function (str) {
  if (str.match(escape)) {
    return (
      '"' +
      str.replace(escape, function (a) {
        var c = meta[a];
        if (typeof c === "string") {
          return c;
        }
        c = a.charCodeAt();
        return (
          "\\u00" + Math.floor(c / 16).toString(16) + (c % 16).toString(16)
        );
      }) +
      '"'
    );
  }
  return '"' + str + '"';
};
$.fn.floatingNumber = function (type, arg1, arg2) {
  var result = "";
  if (type == "addition") {
    var r1, r2, m;
    try {
      r1 = arg1.toString().split(".")[1].length;
    } catch (e) {
      r1 = 0;
    }
    try {
      r2 = arg2.toString().split(".")[1].length;
    } catch (e) {
      r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2));
    result = (Math.round(arg1 * m) + Math.round(arg2 * m)) / m;
  } else if (type == "subtraction") {
    var r1, r2, m, n;
    try {
      r1 = arg1.toString().split(".")[1].length;
    } catch (e) {
      r1 = 0;
    }
    try {
      r2 = arg2.toString().split(".")[1].length;
    } catch (e) {
      r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2));
    n = r1 >= r2 ? r1 : r2;
    result = parseFloat(
      ((Math.round(arg1 * m) - Math.round(arg2 * m)) / m).toFixed(n)
    );
  } else if (type == "multiply") {
    var m = 0,
      s1 = arg1.toString(),
      s2 = arg2.toString();
    try {
      m += s1.split(".")[1].length;
    } catch (e) {}
    try {
      m += s2.split(".")[1].length;
    } catch (e) {}
    result =
      (Number(s1.replace(".", "")) * Number(s2.replace(".", ""))) /
      Math.pow(10, m);
  } else if (type == "division") {
    var t1 = 0,
      t2 = 0,
      r1,
      r2;
    try {
      t1 = arg1.toString().split(".")[1].length;
    } catch (e) {}
    try {
      t2 = arg2.toString().split(".")[1].length;
    } catch (e) {}
    with (Math) {
      r1 = Number(arg1.toString().replace(".", ""));
      r2 = Number(arg2.toString().replace(".", ""));
      result = (r1 / r2) * pow(10, t2 - t1);
    }
  }
  return result;
};
Number.prototype.add = function (arg) {
  return $("html").floatingNumber("addition", arg, this);
};
Number.prototype.sub = function (arg) {
  return $("html").floatingNumber("subtraction", this, arg);
};
Number.prototype.mul = function (arg) {
  return $("html").floatingNumber("multiply", arg, this);
};
Number.prototype.div = function (arg) {
  return $("html").floatingNumber("division", this, arg);
};
$.fn.priceShow = function () {
  var $price = 0;
  $(this)
    .find(".price_data[data]")
    .each(function () {
      $price = parseFloat($(this).attr("data")).mul(
        parseFloat(zuoooo_config.currency_rate)
      );
      $(this).text($("html").iconvPriceFormat($price, 2, "", 1));
    });
};
$.fn.iconvPriceFormat = function (price) {
  var method = typeof arguments[1] == "undefined" ? 0 : arguments[1],
    currency = typeof arguments[2] == "undefined" ? "" : arguments[2],
    is_currency = typeof arguments[3] == "undefined" ? 0 : arguments[3],
    symbol = zuoooo_config.currency_symbols,
    price = parseFloat(price),
    result = 0;
  currency == "" && (currency = zuoooo_config.currency);
  if (method == 0) {
    result = Math.ceil(price.mul(10000).div(100)).div(100).toFixed(2);
    is_currency == 1 &&
      currency &&
      (result = $("html").currencyFormat(result, currency));
    result = symbol + result;
  } else if (method == 1) {
    result = symbol;
  } else {
    result = Math.ceil(price.mul(10000).div(100)).div(100).toFixed(2);
    is_currency == 1 &&
      currency &&
      (result = $("html").currencyFormat(result, currency));
  }
  return result;
};
$.fn.currencyFormat = function (price, currency) {
  var result = 0;
  price = parseFloat(price);
  switch (currency) {
    case "USD":
    case "GBP":
    case "CAD":
    case "AUD":
    case "CHF":
    case "HKD":
    case "ILS":
    case "MXN":
    case "CNY":
    case "SAR":
    case "SGD":
    case "NZD":
    case "AED":
      result = price.formatMoney(2, ".", ",");
      break;
    case "RUB":
      result = price.formatMoney(2, ",", " ");
      break;
    case "EUR":
    case "BRL":
    case "ARS":
      result = price.formatMoney(2, ",", ".");
      break;
    case "CLP":
    case "NOK":
    case "DKK":
    case "COP":
      result = price.formatMoney(0, "", ".");
      break;
    case "JPY":
    case "SEK":
    case "KRW":
    case "INR":
    case "TWD":
      result = price.formatMoney(0, "", ",");
      break;
    default:
      result = price.formatMoney(2, ".", ",");
      break;
  }
  return result;
};
$.fn.visualSrcoll = function (data) {
  data = $.extend(
    {
      obj: $(this),
      init: function () {
        this.self = data.obj.html();
        this.html = "";
        this.number = data.number;
        this.index = 0;
        this.speed = data.speed || 300;
        this.count = 4;
        this.isTouch = data.isTouch || 0;
        this.element = data.obj[0];
        this.callback = data.callback || "";
        if (!this.element) {
          return false;
        }
        if (this.element.addEventListener) {
          if (this.isTouch == 1) {
            this.element.addEventListener("touchstart", this, false);
            this.element.addEventListener("touchmove", this, false);
            this.element.addEventListener("touchend", this, false);
          }
          window.addEventListener("resize", this, false);
        }
        if (
          typeof data.number == "undefined" &&
          $(".box_visual_srcoll").size() > 0
        ) {
          this.number = $(".box_visual_srcoll").size();
        }
        if (
          typeof data.number == "undefined" &&
          $(".box_visual_srcoll").size() == 0
        ) {
          this.number = 0;
        }
        this.html += '<div class="srcoll_list">';
        this.html +=
          '<a href="javascript:;" rel="nofollow" class="srcoll_btn srcoll_btn_prev" data-btn-srcoll="' +
          this.number +
          '" data-srcoll-direction="prev"></a>';
        this.html +=
          '<a href="javascript:;" rel="nofollow" class="srcoll_btn srcoll_btn_next" data-btn-srcoll="' +
          this.number +
          '" data-srcoll-direction="next"></a>';
        this.html +=
          '<div class="srcoll_suit" style="width:100%; overflow:hidden;">';
        this.html += '<div class="srcoll_suit_box">' + this.self + "</div>";
        this.html += "</div>";
        this.html += '</div">';
        data.obj
          .addClass("box_visual_srcoll")
          .attr("data-box-srcoll", this.number)
          .html(this.html);
        this.setup();
        this.bind();
        if ($.isFunction(this.callback)) {
          this.callback();
        }
      },
      setup: function () {
        this.suit = data.obj.find(".srcoll_list .srcoll_suit");
        this.box = data.obj.find(".srcoll_list .srcoll_suit_box");
        this.box.element = this.box[0];
        this.children = this.box.children();
        this.length = this.children.size();
        if (this.children.eq(0)[0].currentStyle) {
          this.cElement = this.children.eq(0)[0].currentStyle;
        } else {
          this.cElement = getComputedStyle(this.children.eq(0)[0], false);
        }
        this.width =
          parseFloat(this.cElement.width) +
          parseFloat(this.cElement.marginRight) +
          parseFloat(this.cElement.marginLeft);
        if (this.length < 2) {
          return false;
        }
        this.box.element.style.width =
          parseFloat(this.length * this.width + 1).toFixed(2) + "px";
        this.slide(this.index, 0);
        for (i = 1; i <= this.length; ++i) {
          if (i * this.width >= this.suit.width()) {
            this.count = i;
            if ((i - 0.5) * this.width >= this.suit.width()) {
              this.count = i - 1;
            }
            break;
          }
        }
      },
      bind: function () {
        $('*[data-btn-srcoll="' + this.number + '"]').on("click", function () {
          $(this).data("srcoll-direction") == "prev"
            ? data.prev()
            : data.next();
        });
      },
      prev: function () {
        if (this.index) {
          this.slide(this.index - 1, this.speed);
        }
      },
      next: function () {
        if (this.index < this.length - this.count) {
          this.slide(this.index + 1, this.speed);
        }
      },
      slide: function (index, speed) {
        var moveWith = index * this.width;
        var Offset = moveWith + this.suit.width() - this.length * this.width;
        if (Offset > 0) {
          moveWith = moveWith - Offset;
        }
        style = this.box.element.style;
        style.webkitTransitionDuration =
          style.MozTransitionDuration =
          style.msTransitionDuration =
          style.OTransitionDuration =
          style.transitionDuration =
            speed + "ms";
        style.MozTransform = style.webkitTransform =
          "translate3d(" + -moveWith + "px, 0, 0)";
        style.msTransform = style.OTransform =
          "translateX(" + -moveWith + "px)";
        this.index = index;
      },
      handleEvent: function (e) {
        var that = this;
        if (!e.touches) {
          e.touches = new Array(e);
          e.scale = false;
        }
        switch (e.type) {
          case "touchstart":
            this.touchStart(e);
            break;
          case "touchmove":
            this.touchMove(e);
            break;
          case "touchend":
            this.touchEnd(e);
            break;
          case "resize":
            this.setup();
            break;
        }
      },
      touchStart: function (e) {
        this.tConfig = {
          pageX: e.touches[0].pageX,
          pageY: e.touches[0].pageY,
          moveX: this.box.element.style.msTransform
            ? parseFloat(
                this.box.element.style.msTransform.replace("translateX(", "")
              )
            : 0,
        };
        this.movingX = 0;
        this.surplus = parseFloat(this.box.width() - this.suit.width()) * -1;
        this.tMoveX = 0;
      },
      touchMove: function (e) {
        if (e.touches.length > 1 || (e.scale && e.scale !== 1)) return;
        this.movingX = e.touches[0].pageX - this.tConfig.pageX;
        if (this.count == 1) {
          this.movingX =
            this.movingX /
            ((this.index == 0 && this.movingX > 0) ||
            (this.index == this.length - this.count && this.movingX < 0)
              ? Math.abs(this.movingX) / this.width + 1
              : 1);
          style = this.box.element.style;
          style.webkitTransitionDuration =
            style.MozTransitionDuration =
            style.msTransitionDuration =
            style.OTransitionDuration =
            style.transitionDuration =
              "0ms";
          style.MozTransform = style.webkitTransform =
            "translate3d(" +
            (this.movingX - this.index * this.width) +
            "px, 0, 0)";
          style.msTransform = style.OTransform =
            "translateX(" + (this.movingX - this.index * this.width) + "px)";
        } else {
          this.tMoveX = parseFloat(this.tConfig.moveX + this.movingX);
          if (
            this.tMoveX > 0 ||
            (this.tMoveX < 0 && this.tMoveX < this.surplus)
          ) {
            this.tMoveX =
              this.tConfig.moveX +
              this.movingX / (Math.abs(this.tMoveX) / this.width + 1);
          }
          style = this.box.element.style;
          style.webkitTransitionDuration =
            style.MozTransitionDuration =
            style.msTransitionDuration =
            style.OTransitionDuration =
            style.transitionDuration =
              "0ms";
          style.MozTransform = style.webkitTransform =
            "translate3d(" + this.tMoveX + "px, 0, 0)";
          style.msTransform = style.OTransform =
            "translateX(" + this.tMoveX + "px)";
        }
      },
      touchEnd: function (e) {
        if (this.movingX == 0) return false;
        if (this.count == 1) {
          var isSlideHalf = 1;
          isBoundary =
            (this.index == 0 && this.movingX > 0) ||
            (this.index == this.length - this.count && this.movingX < 0);
          this.slide(
            this.index +
              (isSlideHalf && !isBoundary ? (this.movingX < 0 ? 1 : -1) : 0),
            this.speed
          );
        } else {
          this.tMoveX = this.tConfig.moveX + this.movingX;
          if (this.tMoveX > 0) {
            this.slide(0, 0);
          } else if (this.tMoveX < 0 && this.tMoveX < this.surplus) {
            this.slide(this.length - 1, 0);
          }
        }
      },
    },
    data
  );
  data.init();
};
$.fn.visualTab = function (data) {
  data = $.extend(
    {
      obj: $(this),
      init: function () {
        this.button = data.button;
        this.box = data.box;
        this.current = data.current || "current";
        this.box_current = data.box_current || "current";
        this.selector = data.obj.find(this.button + ":visible").selector;
        this.selectorBox = data.obj.find(this.box).selector;
        this.bind();
      },
      bind: function () {
        data.obj.find(this.button + ":visible").on("click", function () {
          index = $(this).index(this.selector);
          data.display(index);
        });
      },
      display: function (index) {
        data.obj
          .find(this.button)
          .eq(index)
          .addClass(this.current)
          .siblings(this.selector)
          .removeClass(this.current);
        data.obj
          .find(this.box)
          .eq(index)
          .show()
          .addClass(this.box_current)
          .siblings(this.selectorBox)
          .hide()
          .removeClass(this.box_current);
      },
    },
    data
  );
  data.init();
};
String.prototype.replaceAll = function (s1, s2) {
  return this.replace(new RegExp(s1, "gm"), s2);
};
$.fn.GetTruePixel = function (options) {
  $.fn.GetTruePixel.defaults = {
    type: "width",
    padding: true,
    border: true,
    margin: false,
  };
  let _this = this;
  let opts = $.extend({}, $.fn.GetTruePixel.defaults, options);
  let result;
  if (opts.type == "width") {
    result = _this[0].getBoundingClientRect().width;
  } else if (opts.type == "height") {
    result = _this[0].getBoundingClientRect().height;
  }
  let type_obj = {
    width: {
      margin: {
        left: "margin-left",
        right: "margin-right",
      },
      padding: {
        left: "padding-left",
        right: "padding-right",
      },
      border: {
        left: "border-left-width",
        right: "border-right-width",
      },
    },
    height: {
      margin: {
        left: "margin-top",
        right: "margin-bottom",
      },
      padding: {
        left: "padding-top",
        right: "padding-bottom",
      },
      border: {
        left: "border-top-width",
        right: "border-bottom-width",
      },
    },
  };
  if (opts.border == false) {
    result =
      result -
      parseFloat(_this.css(type_obj[opts.type].border.left)) -
      parseFloat(_this.css(type_obj[opts.type].border.right));
  }
  if (opts.padding == false) {
    result =
      result -
      parseFloat(_this.css(type_obj[opts.type].padding.left)) -
      parseFloat(_this.css(type_obj[opts.type].padding.right));
  }
  if (opts.margin == true) {
    result =
      result +
      parseFloat(_this.css(type_obj[opts.type].margin.left)) +
      parseFloat(_this.css(type_obj[opts.type].margin.right));
  }
  return result;
};
$.fn.serializeObject = function () {
  var self = this,
    json = {},
    push_counters = {},
    patterns = {
      validate: /^[a-zA-Z][a-zA-Z0-9_-]*(?:\[(?:\d*|[a-zA-Z0-9_-]+)\])*$/,
      key: /[a-zA-Z0-9_-]+|(?=\[\])/g,
      push: /^$/,
      fixed: /^\d+$/,
      named: /^[a-zA-Z0-9_-]+$/,
    };
  this.build = function (base, key, value) {
    base[key] = value;
    return base;
  };
  this.push_counter = function (key) {
    if (push_counters[key] === undefined) {
      push_counters[key] = 0;
    }
    return push_counters[key]++;
  };
  $.each($(this).serializeArray(), function () {
    if (!patterns.validate.test(this.name)) {
      return;
    }
    var k,
      keys = this.name.match(patterns.key),
      merge = this.value,
      reverse_key = this.name;
    while ((k = keys.pop()) !== undefined) {
      reverse_key = reverse_key.replace(new RegExp("\\[" + k + "\\]$"), "");
      if (k.match(patterns.push)) {
        merge = self.build([], self.push_counter(reverse_key), merge);
      } else if (k.match(patterns.fixed)) {
        merge = self.build([], k, merge);
      } else if (k.match(patterns.named)) {
        merge = self.build({}, k, merge);
      }
    }
    json = $.extend(true, json, merge);
  });
  return json;
};
function array_max(arr) {
  if (arr && typeof arr === "object") {
    return Object.values(arr).reduce((p, v) => (p > v ? p : v));
  }
  return null;
}
function array_min(arr) {
  if (arr && typeof arr === "object") {
    return Object.values(arr).reduce((p, v) => (p < v ? p : v));
  }
  return null;
}
$.fn.shareThis = function (type, title, url) {
  let image = "";
  let back_url = "";
  let e_url = "";
  if (url == undefined) {
    url = window.location.href;
  }
  if (url.indexOf("#") > 0) {
    url = url.substring(0, url.indexOf("#"));
  }
  if (type == "pinterest" && $(".container .con img:eq(0)").length) {
    image = $(".container .con img:eq(0)").attr("src");
    if (image.indexOf("ueeshop.ly200-cdn.com") != -1) {
      image = $(".container .con img:eq(0)").attr("src");
    } else {
      image =
        window.location.protocol +
        "//" +
        window.location.host +
        $(".container .con img:eq(0)").attr("src");
    }
  }
  if (image != "" && image != undefined) {
    image = encodeURIComponent(image);
  }
  e_url = encodeURIComponent(url);
  title = encodeURIComponent(title);
  switch (type) {
    case "delicious":
      back_url = "https://delicious.com/post?title=" + title + "&url=" + e_url;
      break;
    case "digg":
      back_url =
        "http://digg.com/submit?phase=2&url=" +
        e_url +
        "&title=" +
        title +
        "&bodytext=&topic=tech_deals";
      break;
    case "reddit":
      back_url = "http://reddit.com/submit?url=" + e_url + "&title=" + title;
      break;
    case "furl":
      back_url =
        "http://www.furl.net/savedialog.jsp?t=" + title + "&u=" + e_url;
      break;
    case "rawsugar":
      back_url =
        "http://www.rawsugar.com/home/extensiontagit/?turl=" +
        e_url +
        "&tttl=" +
        title;
      break;
    case "stumbleupon":
      back_url =
        "http://www.stumbleupon.com/submit?url=" + e_url + "&title=" + title;
      break;
    case "blogmarks":
      break;
    case "facebook":
      back_url =
        "http://www.facebook.com/share.php?src=bm&v=4&u=" +
        e_url +
        "&t=" +
        title;
      break;
    case "technorati":
      back_url = "http://technorati.com/faves?sub=favthis&add=" + e_url;
      break;
    case "spurl":
      back_url =
        "http://www.spurl.net/spurl.php?v=3&title=" + title + "&url=" + e_url;
      break;
    case "simpy":
      back_url =
        "http://www.simpy.com/simpy/LinkAdd.do?title=" +
        title +
        "&href=" +
        e_url;
      break;
    case "ask":
      break;
    case "google":
      back_url =
        "http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" +
        e_url +
        "&title=" +
        title;
      break;
    case "netscape":
      back_url =
        "http://www.netscape.com/submit/?U=" + e_url + "&T=" + title + "&C=";
      break;
    case "slashdot":
      back_url =
        "http://slashdot.org/bookmark.pl?url=" + url + "&title=" + title;
      break;
    case "backflip":
      back_url =
        "http://www.backflip.com/add_page_pop.ihtml?title=" +
        title +
        "&url=" +
        e_url;
      break;
    case "bluedot":
      back_url = "http://bluedot.us/Authoring.aspx?u=" + e_url + "&t=" + title;
      break;
    case "kaboodle":
      back_url =
        "http://www.kaboodle.com/za/selectpage?p_pop=false&pa=url&u=" + e_url;
      break;
    case "squidoo":
      back_url = "http://www.squidoo.com/lensmaster/bookmark?" + e_url;
      break;
    case "twitter":
      back_url = "https://twitter.com/share?text=" + title + "&url=" + e_url;
      break;
    case "pinterset":
      back_url =
        "http://pinterest.com/pin/create/button/?url=" +
        e_url +
        "&media=" +
        image +
        "&description=" +
        title;
      break;
    case "vk":
      back_url = "http://vk.com/share.php?url=" + url;
      break;
    case "bluedot":
      back_url =
        "http://blinkbits.com/bookmarklets/save.php?v=1&source_url=" +
        e_url +
        "&title=" +
        title;
      break;
    case "blinkList":
      back_url =
        "http://blinkbits.com/bookmarklets/save.php?v=1&source_url=" +
        e_url +
        "&title=" +
        title;
      break;
    case "linkedin":
      back_url =
        "http://www.linkedin.com/cws/share?url=" + e_url + "&title=" + title;
      break;
    case "googleplus":
      back_url = "https://plus.google.com/share?url=" + e_url;
      break;
    case "line":
      back_url = "https://social-plugins.line.me/lineit/share?url=" + e_url;
      break;
    case "whatsapp":
      back_url = "https://api.whatsapp.com/send/?text=" + e_url;
      break;
    case "tumblr":
      back_url =
        "https://www.tumblr.com/widgets/share/tool?posttype=link&canonicalUrl=" +
        e_url;
      break;
    case "weibo":
      back_url =
        "http://service.weibo.com/share/share.php/?url=" +
        e_url +
        "&title=" +
        title +
        "&pic=" +
        image;
      break;
    case "tencentqq":
      back_url =
        "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=" +
        e_url +
        "&title=" +
        title +
        "&summary=" +
        e_url +
        "&pics=" +
        image;
      break;
    case "wechat_web":
      back_url = "https://web.wechat.com/";
      break;
    case "wechat_app":
      back_url = "weixin://";
      break;
  }
  window.open(back_url, "bookmarkWindow");
};
$.fn.fileUploadAdd = function (data) {
  let files = data.files;
  for (let i = 0; i < files.length; i++) {
    let file = files[i];
    let reader = new FileReader();
    reader.onload = function (theFile) {
      let image = new Image();
      image.onload = function () {
        file["width"] = this.width;
        file["height"] = this.height;
      };
      image.src = theFile.target.result;
    };
    reader.readAsDataURL(file);
  }
};
